<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'礼品列表'),
	array('op'=>'edit','title'=>'添加礼品'),	
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$list=pdo_getall('jy_weishop_live_liping',$params,$fields,'','id desc');
	$return['list']=$list;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_op'=>'del','list'=>array(
			array('name'=>'title','title'=>'礼品名称','type'=>'string'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'picurl','title'=>'活动封面','type'=>'image'),
			array('name'=>'jifen','title'=>'积分数/赞数','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
		),'action' => 
		    array (
			       array('type'=>'href','op'=>'edit','title'=>'编辑'),
		),)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_weishop_live_liping',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$rid=$this->session('rid');
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>$tabs,
		'edit'=>array(
					array('name'=>'title','title'=>'礼品名称','type'=>'string'),
					array('name'=>'picurl','title'=>'礼品封面','type'=>'image'),
					array('name'=>'price','title'=>'礼品价格','type'=>'string'),
					array('name'=>'jifen','title'=>'礼品积分/赞数','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'picurl'=>trim($postdata['picurl']),
		'price'=>$postdata['price'],
		'jifen'=>intval($postdata['jifen']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_weishop_live_liping',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_weishop_live_liping',$data);
		$id=pdo_insertid();
	}
	exi('操作成功！','','goback');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择礼品！','','list');
	}
	pdo_delete('jy_weishop_live_liping',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的礼品！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_weishop_live_liping',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}